<?php if (!defined('THINK_PATH')) exit();?><!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>测试 - 课堂问答</title>
    <!-- Bootstrap -->
<!--<link href="//cdn.bootcss.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet">-->
<!--你自己的样式文件 -->
<link rel="stylesheet" type="text/css" href="/root/mynet/5/quizzhku/1/Public/Css/bootstrap.min.css" />
<link rel="stylesheet" type="text/css" href="/root/mynet/5/quizzhku/1/Public/Css/base.css" />
<link rel="stylesheet" type="text/css" href="/root/mynet/5/quizzhku/1/Public/Css/fullpage.css" />
<link rel="stylesheet" type="text/css" href="/root/mynet/5/quizzhku/1/Public/Css/font-awesome.min.css" />
<!-- <link rel="stylesheet" type="text/css" href="/root/mynet/5/quizzhku/1/Public/Css/login.css" /> -->
<!-- <link href="css/your-style.css" rel="stylesheet">      -->   
<!-- 以下两个插件用于在IE8以及以下版本浏览器支持HTML5元素和媒体查询，如果不需要用可以移除 -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
<script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
<![endif]-->
<!-- 如果要使用Bootstrap的js插件，必须先调入jQuery -->
<!--<script src="http://cdn.bootcss.com/jquery/2.0.0/jquery.js"></script>-->
<script type="text/javascript" src="/root/mynet/5/quizzhku/1/Public/Js/jquery.min.js"></script>
<script type="text/javascript" src="/root/mynet/5/quizzhku/1/Public/Js/fullpage.js"></script>
<!-- 包括所有bootstrap的js插件或者可以根据需要使用的js插件调用　-->
<script type="text/javascript" src="/root/mynet/5/quizzhku/1/Public/Js/bootstrap.min.js"></script>
<script type="text/javascript" src="/root/mynet/5/quizzhku/1/Public/Js/base.js"></script>
<script type="text/javascript" src="/root/mynet/5/quizzhku/1/Public/Js/md5.js"></script>
<script type="text/javascript" src="/root/mynet/5/quizzhku/1/Public/Js/vue.js"></script>
<script type="text/javascript" src="/root/mynet/5/quizzhku/1/Public/Js/Chart.min.js"></script>
    
    <link rel="stylesheet" type="text/css" href="/root/mynet/5/quizzhku/1/Public/Css/quiz.css" />
    <link rel="stylesheet" type="text/css" href="/root/mynet/5/quizzhku/1/Public/Css/header.css" />

</head>
<body>
    
    <div id="title">
    <img/>
    <div class="dropdown" id="dropdown">
        <a href="##" data-toggle="dropdown" class="dropdown-toggle">
            <?php echo (session('name')); ?><span class="caret"></span>
        </a>
        <ul class="dropdown-menu pull-right">
            <li ><a href="/root/mynet/5/quizzhku/1/index.php/Home/TeaSettings/info"><span class="glyphicon glyphicon-user"></span> 个人设置</a></li>
            <li class="divider"></li>
            <li ><a href="/root/mynet/5/quizzhku/1/index.php/Home/Auth/logout"><span class="glyphicon glyphicon-log-out"></span> 安全退出</a></li>
        </ul>
    </div>
    <div class="classInfo">
        <h1><?php echo ($classInfo["cla_name"]); ?> - <?php echo ($classInfo["cou_name"]); ?></h1>
        <p>使用以下邀请码邀请学生加课</p>
        <p><?php echo ($classInfo["cla_code"]); ?></p>
        <input type="hidden" id="cla_id" value="<?php echo ($classInfo["cla_id"]); ?>"/>
    </div>
</div>
<div class="navbar navbar-inverse">
    <div class="row">
        <div class="navbar-header col-md-4 ">
            <button class="navbar-toggle" type="button" data-toggle="collapse" data-target=".navbar-responsive-collapse">
                <span class="sr-only">Toggle Navigation</span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
            </button>
            <a href="/root/mynet/5/quizzhku/1/index.php/Home/TeaClass/classes" class="navbar-brand left">
                <i class="fa fa-long-arrow-left"></i>
                课堂
            </a>
        </div>
        <div class="collapse navbar-collapse navbar-responsive-collapse">
            <div class="col-md-4 ">
                <ul class="nav navbar-nav nav-class">
                    <li <?php if(quiz == quiz): ?>class="active"<?php endif; ?>><a href="/root/mynet/5/quizzhku/1/index.php/Home/TeaQuiz/quiz?cad=<?php echo ($classInfo["cla_id"]); ?>">测试</a></li>
                    <li <?php if(quiz == student): ?>class="active"<?php endif; ?>><a href="/root/mynet/5/quizzhku/1/index.php/Home/TeaClass/classStuInfo?cad=<?php echo ($classInfo["cla_id"]); ?>">成员</a></li>
                    <li <?php if(quiz == grade): ?>class="active"<?php endif; ?>><a href="/root/mynet/5/quizzhku/1/index.php/Home/QuizResult/grade?cad=<?php echo ($classInfo["cla_id"]); ?>">成绩</a></li>
                </ul>
            </div>
        </div>
    </div>
</div>

    
	<div class="alert alert-danger hidden" role="alert"></div>
    <div class="alert alert-success hidden" role="alert"></div>
    <div class="container">
    	<div class="row">
    		<div class="col-md-10 col-md-offset-1">
    			<div class="release">
    				<a href="javasript:;"><span class="glyphicon glyphicon-edit"></span> 发布测试</a>
    			</div>
				<div class="panel panel-default" id="release-box">
					<div class="panel-body">
						<form class="form-horizontal">
							<div class="form-group">
                                <label class="col-sm-2 control-label">题目名称</label>
                                <div class="col-sm-10">
    			                    <input type="text" class="form-control quiz-name" v-model="qusName" placeholder="测试名称">
                                </div>
    						</div>
                            <div class="form-group">
                                <label class="col-sm-2 control-label">题目简介</label>
                                <div class="col-sm-10">
                                    <textarea class="form-control quiz-remark" rows="2" v-model="qusRemark"> </textarea>
                                </div>
                            </div>
						</form>
					</div>
    				<div class="panel-footer">
    					<button class="btn btn-default btn-import-quiz" data-toggle="modal" data-target="#import-quiz-modal">从其他班级导入</button>
    					<button class="btn btn-primary pull-right btn-add-quiz" v-on:click="addQus">确定</button>
    					<button class="btn btn-default pull-right" id="btn-release-cancel" v-on:click="cancel">取消</button>
    				</div>
				</div>
    		</div>
    	</div>
        <?php if($pageInfo['count'] < 1): ?><div class="col-md-10 col-md-offset-1 display-hint">
                <p>点击上方按钮可以发布测试。</p>
            </div><?php endif; ?>
        <?php if(is_array($quiz)): $i = 0; $__LIST__ = $quiz;if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$quiz_item): $mod = ($i % 2 );++$i;?><div class="row" value="<?php echo ($quiz_item["qus_id"]); ?>">
                <div class="col-md-10 col-md-offset-1">
                    <div class="panel panel-default quiz-box">
                        <div class="panel-body">
                            <div class="box-title">
                                <span class="text-muted"><?php echo ($quiz_item["qus_create_time"]); ?></span>
                                <div class="dropdown pull-right">
                                    <a class="dropdown-toggle" data-toggle="dropdown" href="javascript:;" aria-haspopup="true" aria-expanded="true">
                                        <span class="glyphicon glyphicon-option-vertical"></span>
                                    </a>
                                    <ul class="dropdown-menu">
                                        <li><a href="javascript:;" class="menu-edit-quiz">编辑标题和简介</a></li>
                                        <li><a href="/root/mynet/5/quizzhku/1/index.php/Home/TeaQuiz/question?qd=<?php echo ($quiz_item["qus_id"]); ?>">编辑试题内容</a></li>
                                        <li><a href="javascript:;" class="menu-delete-quiz">删除</a></li>
                                    </ul>
                                </div>
                                <p class="pull-right">
                                    <?php if($quiz_item["qus_status"] == 0): ?>未使用
                                    <?php elseif($quiz_item["qus_status"] == 1): ?>
                                        已发布
                                    <?php elseif($quiz_item["qus_status"] == 2): ?>
                                        已结束<?php endif; ?>
                                </p>
                            </div>
                            <div class="box-body">
                                <div class="box-body-left pull-left">
                                    <h4><a href="/root/mynet/5/quizzhku/1/index.php/Home/TeaQuiz/question?qd=<?php echo ($quiz_item["qus_id"]); ?>"><?php echo ($quiz_item["qus_name"]); ?></a></h4>
                                    <p><?php echo ($quiz_item["qus_remark"]); ?></p>
                                </div>
                                <div class="box-body-right pull-right">
                                    <p class="pull-right">
                                        <a href="/root/mynet/5/quizzhku/1/index.php/Home/QuizResult/grade?cad=<?php echo ($classInfo["cla_id"]); ?>"><?php echo ($quiz_item["lackNum"]); ?></a>
                                        <span href="" class="text-danger">未交</span>
                                    </p>
                                    <?php if($quiz_item["qus_status"] == 2): ?><p class="pull-right">
                                            <a href="/root/mynet/5/quizzhku/1/index.php/Home/QuizResult/analyze?qd=<?php echo ($quiz_item["qus_id"]); ?>"><?php echo ($quiz_item["passNum"]); ?></a>
                                            <span href="" class="text-primary">及格</span>
                                        </p><?php endif; ?>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="panel panel-default edit-box">
                        <div class="panel-body">
                            <form class="form-horizontal">
                                <div class="form-group">
                                    <label class="col-sm-2 control-label">测试名称</label>
                                    <div class="col-sm-10">
                                        <input type="text" class="form-control" placeholder="测试名称">
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label class="col-sm-2 control-label">题目简介</label>
                                    <div class="col-sm-10">
                                        <textarea class="form-control edit-quiz-remark" rows="2" > </textarea>
                                    </div>
                                </div>
                            </form>
                        </div>
                        <div class="panel-footer">
                            <button class="btn btn-primary pull-right btn-edit-quiz">确定</button>
                            <button class="btn btn-default pull-right btn-edit-cancel">取消</button>
                            <div style="clear:right"></div>
                        </div>
                    </div>
                </div>
            </div><?php endforeach; endif; else: echo "" ;endif; ?>
        <!-- count:课程个数 page:总页数 np:当前页数 -->
        <div class="row">
            <?php if($pageInfo['page'] > 1): ?><div class="col-md-3 col-md-offset-5">
                    <ul class="pagination">
                        <li><a href="/root/mynet/5/quizzhku/1/index.php/Home/TeaQuiz/quiz?cad=<?php echo ($classInfo['cla_id']); ?>&amp;np=1">&laquo;首页</a></li>
                        <?php if($pageInfo['np']-1 > 0): ?><li><a href="/root/mynet/5/quizzhku/1/index.php/Home/TeaQuiz/quiz?cad=<?php echo ($classInfo['cla_id']); ?>&amp;np=<?php echo ($pageInfo['np']-1); ?>"><?php echo ($pageInfo['np']-1); ?></a></li><?php endif; ?>
                        <li class="active"><a href="javasript:;"><?php echo ($pageInfo["np"]); ?></a></li>
                        <?php if($pageInfo['np']+1 <= $pageInfo['page']): ?><li><a href="/root/mynet/5/quizzhku/1/index.php/Home/TeaQuiz/quiz?cad=<?php echo ($classInfo['cla_id']); ?>&amp;np=<?php echo ($pageInfo['np']+1); ?>"><?php echo ($pageInfo['np']+ 1); ?></a></li><?php endif; ?>
                        <li><a href="/root/mynet/5/quizzhku/1/index.php/Home/TeaQuiz/quiz?cad=<?php echo ($classInfo['cla_id']); ?>&amp;np=<?php echo ($pageInfo["page"]); ?>">末页&raquo;</a></li>
                    </ul> 
                </div><?php endif; ?>
        </div>
    </div>
    <!-- 删除测试modal -->
    <div class="modal fade" id="del-quiz-modal" role="dialog" aria-labelledby="del-class">
        <div class="modal-dialog modal-sm">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
                    <h4 class="modal-title text-danger">删除试卷</h4>
                </div>
                <div class="modal-body">
                    <p>是否删除测试</p>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                    <button type="button" class="btn btn-danger btn-del">删除</button>
                </div>
            </div>
        </div>
    </div>
    <!-- 导入试卷modal -->
    <div class="modal fade" id="import-quiz-modal" role="dialog" aria-labelledby="del-class">
        <div class="modal-dialog modal-lg">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
                    <h4 class="modal-title">导入试卷</h4>
                </div>
                <div class="modal-body">
                    <div class="row">
                        <div class="col-md-3 col-md-offset-9">
                            <select class="form-control choose-course" v-on:change="reloadImportQuiz" v-model="selClass">
                                <option value="disable">选择一个班级</option>
                                <option v-for="cla in classes" v-bind:value="cla.cla_id">{{ cla.cla_name }}</option>
                            </select>
                        </div>
                    </div>
                    <div class="row other-panels">
                        <template v-for="qus in quses">
                            <div class="col-md-4" v-on:click="chooseQus($index, $event)">
                                <div class="panel panel-default">
                                    <div class="panel-heading">
                                        <span class="glyphicon glyphicon-check"></span>
                                        <h4>{{ qus.qus_name }}</h4>
                                        <p>{{ qus.qus_remark }}</p>
                                    </div>
                                </div>
                            </div>
                        </template>
                    </div>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                    <button type="button" class="btn btn-primary btn-import" v-on:click="importQus">导入</button>
                </div>
            </div>
        </div>
    </div>

    <script type="text/javascript">

        function initReleaseVm() {
            releaseVm = new Vue({
                el: "#release-box",
                data: {
                    qusName: "",
                    qusRemark: "",
                    qusId: "",
                    isFormImport: false,
                },
                methods: {
                    addQus: function() {
                        if (this.isFormImport) {
                            postApi("/root/mynet/5/quizzhku/1/index.php/Home/TeaQuiz/importQuiz", {class_cla_id:"<?php echo ($classInfo["cla_id"]); ?>", qus_name:this.qusName,
                                qus_remark:this.qusRemark, qus_id:this.qus_id}, function(err, data) {
                                if (err) {
                                    showError(err.message);
                                } else {
                                    showSuccessReload(data.message);
                                }
                            });
                        } else {
                            postApi("/root/mynet/5/quizzhku/1/index.php/Home/TeaQuiz/addQuiz", {class_cla_id:"<?php echo ($classInfo["cla_id"]); ?>", qus_name:this.qusName,
                                qus_remark:this.qusRemark}, function(err, data) {
                                if (err) {
                                    showError(err.message);
                                } else {
                                    showSuccessReload(data.message);
                                }
                            });
                        }
                    },
                    cancel: function() {
                        $(".release").show();
                        $("#release-box").hide();
                        this.isFormImport = false;
                        this.qusName = "";
                        this.qusRemark = "";
                        qusId =  "";
                    }
                }
            })
        }

        // 初始化其他班级
        function initImportVm(classes) {
            importVm.classes = classes;
        }

        $(function() {
            importVm = new Vue({
                el: "#import-quiz-modal",
                data: {
                    quses: {},
                    classes: [],
                    selClass: "disable",
                    chooseQusIndex: -1,
                },
                methods: {
                    reloadImportQuiz: function() {
                        if (this.selClass == "disable")
                            return;
                        postApi("/root/mynet/5/quizzhku/1/index.php/Home/TeaQuiz/getOtherClassQuiz", {class_cla_id:this.selClass}, function(err, data) {
                            if (err) {
                                showError(err.message);
                            } else {
                                importVm.chooseQusIndex = -1;
                                importVm.quses = data.data;
                            }
                        });

                    },
                    importQus: function(event) {
                        if (this.chooseQusIndex == -1) {
                            showError("请选择一个试卷");
                            return;
                        }
                        releaseVm.qusName = this.quses[this.chooseQusIndex].qus_name;
                        releaseVm.qusRemark = this.quses[this.chooseQusIndex].qus_remark;
                        releaseVm.qusId = this.quses[this.chooseQusIndex].qus_id;
                        releaseVm.isFormImport = true;
                        $(this.$el).modal("toggle");
                    },
                    chooseQus: function(index, event) {
                        var objChoose = $(event.target).parents(".panel");
                        $(this.$el).find(".panel-heading").removeClass("panel-active");
                        $(this.$el).find(".panel-heading span").removeClass("active");
                        objChoose.find(".panel-heading").addClass("panel-active");
                        objChoose.find(".panel-heading span").addClass("active");
                        this.chooseQusIndex = index;
                    } 
                }

            })
        })

    	$(function() {

            //背景的设置
            var bg = $("#cla_id").val() % 5 + 1;
            $("#title img").prop("src","/root/mynet/5/quizzhku/1/Public/Images/" + bg + ".jpg");
            //班级基本信息的显示
            $(".classInfo").css("opacity","1");

    		// 隐藏和显示发布题目面板
            var release_box = $("#release-box"),
                release = $(".release");
    		release_box.hide(); // 初始化vue对象
            initReleaseVm();
    		$(".release a").click(function() {
    			release.hide();
    			release_box.show();
    		});

            // 显示编辑试题面板
            $(".edit-box").hide();
            $(".menu-edit-quiz").click(function() {
                /*quiz_box.parent().append($(clone_release_box));
                $(clone_release_box).show();*/
                var quiz_box = $(this).parents(".quiz-box");
                quiz_box.hide();
                quiz_box.next().show();

                var cur_row = $(this).parents(".row")
                var old_name = cur_row.find(".box-body-left h4").text();
                var old_remark = cur_row.find(".box-body-left p").text();
                cur_row.find(".edit-quiz-name").val(old_name);
                cur_row.find(".edit-quiz-remark").val(old_remark);
                cur_row.find(".btn-edit-quiz").click(function() {
                    var quiz_name = cur_row.find(".edit-quiz-name").val();
                    var quiz_remark = cur_row.find(".edit-quiz-remark").val();
                    var quiz_id = cur_row.attr("value");
                    postApi("/root/mynet/5/quizzhku/1/index.php/Home/TeaQuiz/updateQuiz", {qus_id:quiz_id, qus_name:quiz_name, 
                        qus_remark:quiz_remark}, function(err, data) {
                        if (err) {
                            showError(err.message);
                        } else {
                            showSuccessReload(data.message);
                        }
                    });
                }); 
                
            });

            $(".btn-edit-cancel").click(function() {
                var edit_box = $(this).parents(".edit-box");
                edit_box.hide();
                edit_box.prev().show();
            });

            var cur_qus = {};
            var del_modal = $("#del-quiz-modal");
            $(".menu-delete-quiz").click(function(){
                cur_qus.qus_id = $(this).parents(".row").attr("value");       //获得试卷的id
                cur_qus.qus_name = $(this).parents(".row").find(".box-body h4").text();
                postApi("/root/mynet/5/quizzhku/1/index.php/Home/TeaQuiz/checkQuiz", {qus_id:cur_qus.qus_id}, function(err, data) {
                    if (err) {
                        showError(err.message);
                    } else {
                        del_modal.modal("toggle");
                        del_modal.find(".modal-body p").text(data.message + " (" + cur_qus.qus_name + ")");
                    }
                });
            });

            del_modal.find(".btn-del").click(function() {
                del_modal.modal("toggle");
                postApi("/root/mynet/5/quizzhku/1/index.php/Home/TeaQuiz/deleteQuiz", {qus_id:cur_qus.qus_id}, function(err, data) {
                    if (err) {
                        showError(err.message);
                    } else {
                        showSuccessReload(data.message);
                    }
                });
            });

            $("#release-box .btn-import-quiz").click(function() {
                var cla_id = "<?php echo ($classInfo["cla_id"]); ?>";
                var cou_id = location.search.substring(1).split("&")[0].split("=")[1];
                postApi("/root/mynet/5/quizzhku/1/index.php/Home/TeaQuiz/getOtherClassInfo", {cla_id:cla_id, cou_id:cou_id}, function(err, data) {
                    if (err) {
                        showError(err.message);
                    } else {
                        initImportVm(data.data);
                    }
                });
            });
    	});
    </script>

</body>